<style>
    .fenlei{width:49%;font-weight:400 !important;background:#f3f3f3;margin-right:1%;height:40px;line-height:40px;padding-left:16px;}
    .fenlei a{float:right;font-size:40px;color:#979797;height:40px;line-height:35px;margin-right:16px;}
    .img-del{height:128px;float:left;position: relative;margin-right:5px;}
    .img-del a{height:20px;position:absolute;bottom:0px;left:0px;background:#000;width:100%;text-align:center;opacity:0.7;filter:alpha(opacity=70);color:#fff;}
    .img-del img{height:100%;padding-top:5px;}
    .clear{clear:both;margin-top:10px;}
</style>
<div class="col-md-12">
    <form action="" method="post" enctype="multipart/form-data">
        <div class="card">
            <div class="card-header">
                <h3 class="card-title">修改产品</h3>
            </div>
            <div class="card-body">
                <div class="form-group">
                    <label>产品名称</label>
                    <input type="text" name="name" value="{$info.name}" class="form-control my-colorpicker1">
                </div>
                <div class="form-group">
                    <label>产品价格</label>
                    <input type="text" name="price" value="{$info.price}" class="form-control my-colorpicker1">
                </div>
                <div class="form-group">
                    <label>物料编号</label>
                    <input type="text" name="wl_no" value="{$info.wl_no}" class="form-control my-colorpicker1">
                </div>
                <div class="form-group">
                    <label>产品类型</label>
                    <div class="form-group" id="fenlei">
                        <foreach name="tar_list_type" item="v">
                            <label class="fenlei" id="del_tag_{$v.id}">{$v.tag_info.name}<a href="javascript:void(0)" onclick="del_tag('{$v.id}')">删除</a></label>
                        </foreach>
                    </div>
                    <a href="javascript:void(0)" data-toggle="modal" data-target="#myModal">添加</a>
                </div>
                <div class="form-group">
                    <label>产品品牌</label>
                    <div class="form-group" id="pinpai_list">
                        <foreach name="tar_list_pinpai" item="v">
                            <label class="fenlei" id="del_tag_{$v.id}">{$v.tag_info.name}<a href="javascript:void(0)" onclick="del_tag('{$v.id}')">删除</a></label>
                        </foreach>
                    </div>
                    <a href="javascript:void(0)" data-toggle="modal" data-target="#Pinpai">添加</a>
                </div>
                <div class="form-group">
                    <label>产品简介</label>
                    <textarea class="ckeditor" name="content" style="width: 100%">{$info.content}</textarea>
                </div>
                <div class="form-group">
                    <label>产品图片</label>
                    <input type="hidden" name="files" value="{$info.file}"/>
                    <div class="form-control" id="add_images" style="min-height:140px;height:<?php echo ceil(count($file_link) / 5) * 140; ?>px">
                        <foreach name="file_link" item="v">
                            <div class="img-del" id='del_{$v.id}'>
                                <img src="Upload/{$v.file_content.file_path}"/>
                                <a href="javascript:del_img('{$info.id}','{$v.id}');">删除</a>
                            </div>
                        </foreach>
                    </div>
                    <input type="file" name="file[]" id="chick_file" class="clear" multiple="multiple">
                </div>
            </div>
            <div class="card-footer">
                <button type="submit" class="btn btn-primary">提交</button>
            </div>
        </div>
    </form>
</div>
<div class="modal fade" id="myModal" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="myModalLabel">
                    请选择标签信息
                </h4>
            </div>
            <div class="modal-body">
                <select class="form-control my-colorpicker1 select2" name="uid" style="width: 100%;">
                    <option value="">请选择</option>
                    <foreach name="tag_list" item="v">
                        <option value="{$v.id}">{$v.name}</option>
                    </foreach>
                </select>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">
                    取消
                </button>
                <button type="button" class="btn btn-primary" id="create_modal">
                    确定
                </button>
            </div>
        </div>
    </div>
</div><div class="modal fade" id="Pinpai" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="myModalLabel">
                    请选择品牌信息
                </h4>
            </div>
            <div class="modal-body">
                <select class="form-control my-colorpicker1 select2 select2_2" name="uid" style="width: 100%;">
                    <option value="">请选择</option>
                    <foreach name="tag_pinpai_list" item="v">
                        <option value="{$v.id}">{$v.name}</option>
                    </foreach>
                </select>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">
                    取消
                </button>
                <button type="button" class="btn btn-primary" id="create_modal_pinpai">
                    确定
                </button>
            </div>
        </div>
    </div>
</div>
<script>
    function del_img(tid, lid) {
        // tid : target_id
        // lid : file_link_id
        // name: target_name
        $.get("{:U('System/del_img')}", {tid: tid, lid: lid, name: 'project'}, function (d) {
            if (d.status == 1) {
                $('#del_' + lid).remove();
            }
        });
    }
    function del_tag(tid) {
        // tid : tag_link_id
        // lid : target_id
        // name: target_name
        $.get("{:U('Tag/delete')}", {tid: tid, lid:"{:I('get.id')}", name: 'project'}, function (d) {
            if (d.status == 1) {
                $('#del_tag_' + tid).remove();
            }
        });
    }
    $(function () {
        $('.fenlei a').html('×');
        $('#myModal').modal('hide')
        $('#create_modal').click(function(){
            var ajax_data = {
                tid:$('select.select2').val(),
                lid:"{:I('get.id')}",
                name:'project'
            };
            $.get("{:U('Tag/create_link')}",ajax_data,function(d){
                if(d.status == 1){
                    $('#fenlei').append('<label class="fenlei"  id="del_tag_' + d.url + '">'+d.info+'<a href="javascript:void(0)" onclick="del_tag(' + d.url + ')">删除</a></label>')
                    $('#myModal').modal('hide')
                }
            });
        });
        $('#Pinpai').modal('hide')
        $('#create_modal_pinpai').click(function(){
            var ajax_data = {
                tid:$('select.select2_2').val(),
                lid:"{:I('get.id')}",
                name:'project'
            };
            $.get("{:U('Tag/create_link')}",ajax_data,function(d){
                if(d.status == 1){
                    $('#pinpai_list').append('<label class="fenlei"  id="del_tag_' + d.url + '">'+d.info+'<a href="javascript:void(0)" onclick="del_tag(' + d.url + ')">删除</a></label>')
                    $('#Pinpai').modal('hide')
                }
            });
        });
        $(".select2").select2();
        $(".select2_2").select2();
        $('#chick_file').change(function(){
            for(var i = 0 ; i < this.files.length ; i ++){
                var file = this.files[i];
                var form = new FormData();
                form.append('ajaxUpload',file);
                form.append('table_name','project');
                form.append('table_id',"{:I('get.id')}");
                $.ajax({
                    url: "{:U('Api/File/upload_ajax')}",
                    async: true,
                    type: 'post',
                    data: form,
                    processData: false,
                    contentType: false,
                    success: function(data){
                        eval('data = '+data);
                        var htmls = '<div class="img-del" id="del_'+data.link_id+'"><img src="__PUBLIC__/Upload/' + data.file_path+'"/><a href="javascript:del_img(\'{$_GET.id}\',\''+data.link_id+'\')">删除</a></div>';
                        $('#add_images').append(htmls)
                    }
                });
            }
            $('#chick_file').val('');
        });
    });
</script>